//注册点击返回上一级事件
function back() {
    let backk = document.querySelector('.back')
    back.onclick = function () {
        history.back()
    }
}


// 国内折扣页面调用方法
function zhekou() {
    (function () {

        let uu = document.querySelector("#nav  ul")
        // 发请求获取数据, 并且渲染列表
        // console.log(uu);
        fetch("http://chst.vip:1234/api/getinlanddiscount")
            .then(body => body.json())
            .then(res => {
                console.log(res)
                let html = "";
                res.result.forEach(item => {
                    html += `
                    <li productId=${item.productId}>
                    <a href='#'>
                    <div class="image">${item.productImg}</div>
                    <div class="title">${item.productName}</div>
                    <p class="price">${item.productPrice}</p>
                    <p class="from">${item.productFrom}</P>
                </a>
                    </li>
                    `
                })
                console.log(html);
                uu.innerHTML = html

                //获取Li元素,注册点击事件

                let lis = [...uu.children];

                // console.log(lis)

                lis.forEach(item => {
                    item.onclick = function () {
                        //获取当前元素的couponId
                        let productId = this.getAttribute("productId")
                        // console.log(couponId)
                        //跳转到详情页
                        location.href = `./zhekouXiang.html?productid=${productId}`
                    }
                })


            })

    })()

}


// 国内折扣详情页面调用方法
function zhekouXiang() {
    (function () {
        let xhr = new XMLHttpRequest();

        let uu = document.querySelector('#product ul')
        let url = location.href;
        let {
            productid
        } = getUrlParams(url);
        xhr.open("get", `http://chst.vip:1234/api/getdiscountproduct?productid=${productid}`, 'true');
        xhr.send(null)
        xhr.onreadystatechange = function () {
            let html = ""

            if (xhr.readyState === 4 && xhr.status === 200) {
                let res = xhr.responseText;
                res = JSON.parse(res);
                console.log(res);

                //let html = ""; //声明一个html结构
                //根据数据 渲染结构
                res.result.forEach(item => {
                    html += `
                    <li>
                    <div class="inFOR">
                        <div class="tiele">
                            <h4>${item.productName}</h4>
                        </div>
                        <div class="other">
                            <span class="mall"> ${item.productFrom}|${item.productTime}</span>
                            <i>${item.productTips}</i>
                            <div>${item.productPrice}</div>
                        </div>
                        <div class="container">
                            <div class="infor2">${item.productInfo}</div>
                            <p>${item.productImg}</p>
                        </div>
                        <div class="city"></div>
                    </div>
                </li>  
                    `

                })
                uu.innerHTML = html
            }
        }

    })()
}





//商品导航页面调用方法
function spdh() {
    (function () {
        let xhr = new XMLHttpRequest();
        let uu = document.querySelector('#nav ul')
        xhr.open("get", "http://chst.vip:1234/api/getsitenav");

        xhr.send(null)

        xhr.onreadystatechange = function () {
            let html = ""
            if (xhr.readyState === 4 && xhr.status === 200) {
                let res = xhr.responseText;
                res = JSON.parse(res);
                console.log(res);

                //let html = ""; //声明一个html结构
                //根据数据 渲染结构
                res.result.forEach(item => {
                    html += `
                    <li>
                    <a href="${item.navHref}">
                       <img src="${item.navImg}">
                        <span> ${item.navTitle}</span>
                    </a>
       
                </li>
                    `
                })
                uu.innerHTML = html
            }
        }

    })()
}

// 优惠券主体页面调用方法
function youhui() {
    (function () {

        let uu = document.querySelector("#nav  ul")
        // 发请求获取数据, 并且渲染列表
        // console.log(uu);
        fetch("http://chst.vip:1234/api/getcoupon")
            .then(body => body.json())
            .then(res => {
                console.log(res)
                let html = "";
                res.result.forEach(item => {
                    html += `
                     <li couponId=${item.couponId}>
                       <img src=" ${item.couponImg}">
                        <b>${item.couponTitle}</b>
                     </li>
                    `
                })
                console.log(html);
                uu.innerHTML = html

                //获取Li元素,注册点击事件

                let lis = [...uu.children];

                // console.log(lis)

                lis.forEach(item => {
                    item.onclick = function () {
                        //获取当前元素的couponId
                        let couponId = this.getAttribute("couponId")
                        // console.log(couponId)
                        //跳转到详情页
                        location.href = `./youhuiList.html?couponid=${couponId}`
                    }
                })
            })

    })()

}

// 优惠券列表页面调用方法
function youhuiList() {
    (function () {
        let xhr = new XMLHttpRequest();
        let carousel = document.querySelector('.carousel .marskSm .Arrinfo')
        let uu = document.querySelector('#product ul')
        let url = location.href;
        let {
            couponid
        } = getUrlParams(url);
        xhr.open("get", `http://chst.vip:1234/api/getcouponproduct?couponid=${couponid}`, 'true');
        xhr.send(null)
        xhr.onreadystatechange = function () {
            let html = ""
            let html2 = ""
            if (xhr.readyState === 4 && xhr.status === 200) {
                let res = xhr.responseText;
                res = JSON.parse(res);
                console.log(res);

                //let html = ""; //声明一个html结构
                //根据数据 渲染结构
                res.result.forEach(item => {
                    html += `
                    <li>
                    <div class="image">${item.couponProductImg}
                    </div>
                    <div class="other">
                        <div class="title">
                            <h4>${item.couponProductName}</h4>
                        </div>
                        <div class="price">
                            <p>${item.couponProductPrice}</p>
                            <div class="time">${item.couponProductTime}</div>
                        </div>
                    </div>
            </li>
                    `
                    html2 += `
                    
                        <li> ${item.couponProductImg}</li> 
                    `
                })

                uu.innerHTML = html
                carousel.innerHTML = html2
                let Arrinfo = document.querySelector('.marskSm .Arrinfo')
                console.log($("#product li"))
                $("#product  li").click(function () {
                    picIndex = $(this).index()
                    Arrinfo.style.left = `-${picIndex * onePicWidth}px`

                    $(".carousel").css({
                        transform: " translateY(1000px)",
                        transition: "all 0.7s ease-in-out 0s"

                    })

                });
                console.log($(".marskSm i"));
                $(".marskSm i").click(function () {

                    $(".carousel").css({
                        transform: " translateY(-1000px)",
                        transition: "all 0.7s ease-in-out 0s"
                    })

                })
                let lis = document.querySelector('.carousel')

                console.log("---------------");
                let onePicWidth = 200; //一张图片的宽度
                let picIndex = 0 //定义一个标记，用于记录图片走了多少张

                $('.carousel .arr .arrow').click(function () {

                    if ($(this).index() == 0) {

                        picIndex--
                        if (picIndex < 0) {
                            picIndex = 0
                            // picIndex = lis.length - 1
                            alert('这是第一页')

                        }
                    } else {
                        picIndex++

                        if (picIndex === lis.length) {
                            picIndex = lis.length - 1
                            alert('这是最后一页')

                        }

                    }


                    console.log(picIndex);
                    animate(Arrinfo, -(picIndex * onePicWidth))

                })

            }
        }


    })()

}





//白菜价页面调用方法
function baicaijia() {
    (function () {
        let uu = document.querySelector("#product  ul")

        // 发请求获取数据, 并且渲染列表
        // console.log(uu);
        fetch("http://chst.vip:1234/api/getbaicaijiaproduct?titleid=0")
            .then(body => body.json())
            .then(res => {
                console.log(res)
                let html = "";
                res.result.forEach(item => {
                    html += `
                    <li>
                 <div class="images">
                 ${item.productImg}
                 </div>
                 <div class="inFOR">
                     <div class="title">
                         <h4>
                        ${item. productName}
                         </h4>
                         <div class="price">
                              ${item.productPrice}
                         </div>
                     </div>
                       <div class="down">
         
                        <div class="bar-down">
                       <div class="bar_in">0%</div>
                        </div>

                                  <span class="yiling">${item.productCouponRemain}</span>

          <div class="click">
              <div class="left">${item.productCoupon}</div>
              <div class="right">${item.productHref}</div>
          </div>

     </div>
    </div>    
    </li>
     `
                })
                uu.innerHTML = html

                TimeHtml()
                yiling()


            })

        function TimeHtml() {
            $(".bar_in").animate({
                left: 0,
                top: 0,
                opacity: 1,
                width: 120,
                borderRadius: "0%"
            }, 4000)
            let i = 0
            let str = " "
            let timer = setInterval(function () {
                str = `${i++}%`
                $(".bar_in").text(str)
                if (i == 101) {
                    clearInterval(timer)
                    console.log(timer);
                }
            }, 40)

        }

        function yiling() {
            let j = 0
            let str2 = ""
            let str3 = ""
            let Timetext = setInterval(function () {
                str2 = `${j++}`
                str3 = 126 - str2
                $('.yiling').text(`已领${str2}张/剩余${str3}张`)
                if (j == 127) {
                    clearInterval(Timetext)
                }

            }, 30)





        }

        // 导航区域

        let marsk = document.querySelector(".marsk  ul")

        // 发请求获取数据, 并且渲染列表
        // console.log(uu);
        fetch("http://chst.vip:1234/api/getbaicaijiatitle?titleId=0")
            .then(body => body.json())
            .then(res => {
                console.log(res)
                let html2 = "";
                res.result.forEach(item => {
                    html2 += `
                    <li>${item.title}</li>
                    `
                })

                marsk.innerHTML = html2

                //获取Li元素,注册点击事件

                let lis = [...marsk.children];
                console.log(lis);
                lis.forEach((item, index) => {


                    item.onclick = function () {
                        console.log(index);
                        $(this).siblings().removeClass("active")
                        console.log(this);
                        this.className = "active"
                        fetch(`http://chst.vip:1234/api/getbaicaijiaproduct?titleid=${index}`)
                            .then(body => body.json())
                            .then(res => {
                                console.log(res)
                                let html3 = "";
                                res.result.forEach(item => {
                                    html3 += `
                                    <li>
                                 <div class="images">
                                 ${item.productImg}
                                 </div>
                                 <div class="inFOR">
                                     <div class="title">
                                         <h4>
                                        ${item. productName}
                                         </h4>
                                         <div class="price">
                                              ${item.productPrice}
                                         </div>
                                     </div>
                         <div class="down">
                         
                         <div class="bar-down">
                             <div class="bar_in">0%</div>
                         </div>
                
                         <span class="yiling">${item.productCouponRemain}</span>
                
                          <div class="click">
                              <div class="left">${item.productCoupon}</div>
                              <div class="right">${item.productHref}</div>
                          </div>
                
                     </div>
                    </div>    
                    </li>  
                                `
                                })

                                uu.innerHTML = html3
                                TimeHtml()
                                yiling()

                            })


                    }
                })

            })



    })()

}




// 省钱控详情页面调用方法
function moneyctrlXiang() {
    (function () {
        let xhr = new XMLHttpRequest();
        let uu = document.querySelector('#product ul')
        let comment = document.querySelector('.comment')
        let url = location.href;
        let {
            productid
        } = getUrlParams(url);
        xhr.open("get", `http://chst.vip:1234/api/getmoneyctrlproduct?productid=${productid}`, 'true');
        xhr.send(null)
        xhr.onreadystatechange = function () {
            let html = ""
            let html2 = ""
            if (xhr.readyState === 4 && xhr.status === 200) {
                let res = xhr.responseText;
                res = JSON.parse(res);
                console.log(res);

                //let html = ""; //声明一个html结构
                //根据数据 渲染结构
                res.result.forEach(item => {
                    html += `
                    <li class="inFOR">
                     <!-- 标题 -->
                   <div class="title">
                       <h4>移动端凑单品：海天 鲜味 生抽 1.28L</h4>
                   </div>
                   <!-- 副标题 -->
                   <div class="other">
                       <span class="mall">${item.productFrom}|${item.productTime}</span>
                       <i>${item.productTips}</i>
                   </div>
                   <!-- 图文内容区域 -->
                   <div class="container">
                       <p>
                           ${item.productImgSm}
                           ${item.productInfo2}
                       </p>
                   </div>
                   <!-- 大图区域 -->
                   <div class="bigimg">
                   ${item.productImgSm}
                   </div>
                   <!-- 地区 -->
                   <div class="city">
                 ${item.productCity}    
           </div>
                </li>
                    `
                    html2 += `
                    <div class="comment">
                    ${item.productComment}
                    </div> 
                    
                    `
                })
                uu.innerHTML = html
                comment.innerHTML = html2
            }
        }

    })()
}


// 比价详情2页面调用方法
function bijia() {
    (function () {
        let url = location.href;
        // console.log(url);
        productid = getUrlParams(url);
        let {
            title,
            categoryid
        } = productid
        // console.log(productid);
        // console.log(title);
        //渲染页面结构函数
        function build(categoryid, pageid = 1) {
            let xhr = new XMLHttpRequest();
            let uu = document.querySelector('.bijia_info ul ')
            // let comment=document.querySelector('.comment')
            // let url = location.href;
            // let { categoryid } = getUrlParams(url);
            xhr.open("get", `http://chst.vip:1234/api/getproductlist?categoryid=${categoryid}&pageid=${pageid}`, 'true');
            xhr.send(null)
            xhr.onreadystatechange = function () {
                let html = ""
                // let html2=""
                if (xhr.readyState === 4 && xhr.status === 200) {
                    let res = xhr.responseText;
                    res = JSON.parse(res);
                    console.log(res);
                    //let html = ""; //声明一个html结构
                    //根据数据 渲染结构
                    res.result.forEach(item => {
                        html += `
                    <li>
                    <a href="./../pages/productlist.html?categoryid=${item.categoryId}&productid=${item.productId}" class="clearfix">
                        <div class="img fl">
                        ${item.productImg}
                        </div>
                        <div class="inFOR">
                            <div class="title">
                                <h4>${item.productName}</h4>
                                <div class="price">${item.productPrice}</div>
                            </div>
                            <div class="other">
                                <span class="take_price">${item.productQuote}</span>
                                <i>${item.productCom}</i>
                            </div>
                        </div>
                    </a>
                </li>
                    `
                        // html2+=`
                        // <div class="comment">
                        // ${item.productComment}
                        // </div> 

                        // `
                    })
                    uu.innerHTML = html
                    // comment.innerHTML=html2
                }
            }
        }
        // 初始渲染页面
        build(categoryid, pageid = 1)
        //筛选框的全部分类后面的名称
        let a = document.createElement('a')
        // console.log(a);
        a.innerText = title + ">"
        let fr = document.querySelector('.fr')
        let subNav = document.querySelector('#subNav')
        subNav.insertBefore(a, fr)
        // 点击分类名称跳转到当前页面的第一页
        a.onclick = function () {
            // 调用函数渲染页面
            build(categoryid, pageid = 1);
        }
        //根据回传的数据渲染分页器中option
        $.ajax({
                url: `http://chst.vip:1234/api/getproductlist?categoryid=${categoryid}&pageid=1`

            })
            .then(res => {
                console.log(res);
                let count = Math.ceil(res.totalCount / res.pagesize)
                let page = document.querySelector('.page')
                // console.log(count);
                let pageText = ''
                for (i = 1; i <= count; i++) {
                    pageText += `<option value="" class="page">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;${i}/${count}</option>`
                }
                page.innerHTML = pageText;
                pageChange(count)

            })

        //翻页器函数
        function pageChange(count) {
            // console.log(count);
            let pageid = 1;
            // 翻页点击事件
            $('.page').click(() => {
                // console.log($(".page")[0].selectedIndex,'---------');
                pageid = $(".page")[0].selectedIndex + 1 //获取索引
                console.log(pageid);
                build(categoryid, pageid)
                if (pageid == 1) {
                    $('.pagePrev')[0].setAttribute('disabled', 'disabled')
                } else if (pageid == count) {
                    $('.pageNext')[0].setAttribute('disabled', 'disabled')
                } else {
                    // console.log('逻辑进来了');
                    $('.pagePrev').removeAttr('disabled')
                    $('.pageNext').removeAttr('disabled')
                }
                // console.log(pageid);
            })
            // 下一页点击事件
            $('.pageNext').click(() => {
                $('.pagePrev').removeAttr('disabled')
                pageid++ //每次被点击的时候 让id自加 请求不同的数据
                // console.log(pageid,'+++++++');
                if (pageid <= count) {
                    $('select.page').get(0).options[pageid - 1].selected = true
                }
                // console.log('下一页' + pageid);
                if (pageid == count) { //当id大于14的时候 停止发送请求
                    $('.pageNext')[0].setAttribute('disabled', 'disabled')
                    // pageid=13;
                    // return
                }
                build(categoryid, pageid)
            })
            // 上一页点击事件
            $('.pagePrev').click(() => {
                $('.pageNext').removeAttr('disabled')
                pageid--; //每次被点击的时候 让id自减 请求不同的数据
                // console.log(pageid,'---------');
                if (pageid >= 0) {
                    $('.page').get(0).options[pageid - 1].selected = true
                }
                // console.log("上一页" + pageid);
                if (pageid == 1) { //当id=0的时候 禁用按钮
                    $('.pagePrev')[0].setAttribute('disabled', 'disabled')
                }
                build(categoryid, pageid)
            })
        }
    })()
}
// 比价详情3页面调用方法
function bijiaList() {
    (function () {
        let url = location.href;
        // console.log(url);
        productid = getUrlParams(url);
        let {
            productid: product,
            categoryid: category
        } = productid
        // console.log(product);
        // console.log(category);
        let uu = document.querySelector('#main .goods')
        //发送请求获取数据，并且渲染商品列表
        fetch(`http://chst.vip:1234/api/getproduct?productid=${product}`)
            .then(body => body.json())
            .then(res => {
                console.log(res);
                let html = ""
                res.result.forEach(item => {
                    html += `<div class="pic">
                ${item.productImg}
            </div>
            <div class="title">
                ${item.productName}
            </div>
            <div class="count">
            <div class="row">
                <div class="left">
                    <span>当前最低</span>
                    <span>￥6000</span>
                </div>
                <div class="right">
                    <span>优选评论</span>
                    <span>8266条</span>
                </div>
            </div>
            </div>
            <div class="price">
                ${item.bjShop}
            </div>`
                })
                uu.innerHTML = html
                return res.result[0].productName
            })
            .then(name => {
                console.log(name);
                //  渲染筛选顶部的分类
                fetch(`http://chst.vip:1234/api/getcategorybyid?categoryid=${category}`)
                    .then(body => body.json())
                    .then(res => {
                        let text = res.result[0].category
                        //筛选框的全部分类后面的名称
                        let a = document.createElement('a')
                        // console.log(a);
                        a.innerText = text + ">"
                        console.log(a);
                        let fr = document.querySelector('.fr')
                        let subNav = document.querySelector('#subNav')
                        subNav.insertBefore(a, fr)
                        a.onclick = function () {
                            history.back()
                        }
                        // 创建商品名称
                        let shopname = document.createElement('a')
                        shopname.innerText = name.substr(0, 6)
                        console.log(shopname);
                        subNav.insertBefore(shopname, fr)

                    })

            })

        let content = document.querySelector('.comment  .content')
        fetch(`http://chst.vip:1234/api/getproductcom?productid=${product}`)
            .then(body => body.json())
            .then(res => {
                console.log(res);
                let html2 = "";
                res.result.forEach(item => {
                    html2 += `
                <div class="content-box">
                                <div class="up">
                                    <div class="comName"> ${item.comName}</div>
                                    <div class="comTime">${item.comTime}</div>
                                </div>
                                <div class="comContent">${item.comContent}</div>
                                <div class="comFrom">${item.comFrom}</div>
                            </div>
                `
                })
                content.innerHTML = html2
            })
    })()
}





// 品牌大全的列表分页页面调用方法
function brand() {
    (function () {
        let url = location.href;
        console.log(url);
        productid = getUrlParams(url);
        let {
            title,
            brandtitleid
        } = productid
        // console.log(productid);
        // console.log(title);
        // console.log(brandtitleid);
        //渲染页面结构函数
        function build(brandtitleid, pagesize = 10) {
            let xhr = new XMLHttpRequest();
            let uu = document.querySelector('.brand_info ul ')
            // let comment=document.querySelector('.comment')
            // let url = location.href;
            xhr.open("get", `http://chst.vip:1234/api/getbrandproductlist?brandtitleid=${brandtitleid}&pagesize=${pagesize}`, 'true');
            xhr.send(null)
            xhr.onreadystatechange = function () {
                let html = ""
                // let html2=""
                if (xhr.readyState === 4 && xhr.status === 200) {
                    let res = xhr.responseText;
                    res = JSON.parse(res);
                    console.log(res);
                    //let html = ""; //声明一个html结构
                    //根据数据 渲染结构
                    res.result.forEach(item => {
                        html += `
                    <li>
                    <a href="./../pages/productlist.html?categoryid=${item.categoryId}&productid=${item.productId}" class="clearfix">
                        <div class="img fl">
                        ${item.productImg}
                        </div>
                        <div class="inFOR">
                            <div class="title">
                                <h4>${item.productName}</h4>
                                <div class="price">${item.productPrice}</div>
                            </div>
                            <div class="other">
                                <span class="take_price">${item.productQuote}</span>
                                <i>${item.productCom}</i>
                            </div>
                        </div>
                    </a>
                </li>
                    `
                        // html2+=`
                        // <div class="comment">
                        // ${item.productComment}
                        // </div> 

                        // `
                    })
                    uu.innerHTML = html
                    // comment.innerHTML=html2
                }
            }
        }
        // // 初始渲染页面
        build(brandtitleid, 10)
        //筛选框的全部分类后面的名称
        let a = document.createElement('a')
        console.log(a);
        a.innerText = title + ">"
        let fr = document.querySelector('.fr')
        let subNav = document.querySelector('#subNav')
        subNav.insertBefore(a, fr)
    })()
}


// brandTitle页面
function brandTitle() {
    (function () {
        //获取品牌商品
        function menu(data) {
            newData = [...data]
            // console.log(newData);
            let html = "" //这个变量用于保存循环创建出来的结构字符串
            newData.forEach(item => {
                html +=
                    ` <li class="brandListLi">
              <div class="smallBrandListTitle"><p>${item.brandTitle}</p><span>▼</span></div>
              <div class="smallBrandList">
                  <ol>
                  </ol>
              </div>
          </li>  `
            })
            $("#brandList>ul").html(html);


            // 页面点击事件
            $(".smallBrandListTitle").on('click', function () {
                $(this).next().slideToggle()
                $(this).css('color', 'gray');
                $(this).parent().siblings().find('.smallBrandListTitle').next().hide(300)
                $(this).parent().siblings().find('.smallBrandListTitle').css('color', 'black');

            })

            newData.forEach((el, index) => {
                $.ajax({
                        url: `http://chst.vip:1234/api/getbrand?brandtitleid=${el.brandTitleId}`
                    })
                    .then(res => {
                        console.log(res);
                        let brandList = ''
                        res.result.forEach((resel, nub) => {
                            // console.log(nub);
                            // console.log(resel.brandTitleId);
                            brandList +=
                                `<li><a href="./../pages/brand.html?title=${resel.brandName}&brandtitleid=${resel.brandId}">
                          <div><span>${nub}</span>  ${resel.brandName}</div>
                          <p>${resel.brandInfo}</p>
                      </a></li>`
                        })
                        // ?title=三星平板电视&brandtitleid=0
                        // console.log($('.brandListLi>.smallBrandList>ol'))
                        //创建页面结构
                        $('.brandListLi>.smallBrandList>ol').eq(index).html(brandList)
                        // console.log($('.brandListLi>.smallBrandList>ol').eq(index).find('div').find('span'));
                        $('.brandListLi>.smallBrandList>ol').eq(index).find('div').find('span').eq(0).css('background', 'red');
                        $('.brandListLi>.smallBrandList>ol').eq(index).find('div').find('span').eq(1).css('background', '#FFA500');
                        $('.brandListLi>.smallBrandList>ol').eq(index).find('div').find('span').eq(2).css('background', '#ADFF2F');
                    })
            })

        }
        $.ajax({
                url: "http://chst.vip:1234/api/getbrandtitle"
            })
            .then(res => {
                console.log(res);
                menu(res.result)
                //循环数据 创建结构
                // return res.result
            })
    })()
}

// category页面
function category() {
    (function () {
        //获取比价商品
        function menu(data) {
            newData = [...data]
            // console.log(newData);
            let html = "" //这个变量用于保存循环创建出来的结构字符串
            newData.forEach(item => {
                html +=
                    `<li class="bigListLi">
                                <div class="smallListTitle"><p>${item.title}</p><span>▼</span></div>
                                <div class="smallList">
                                   <ol>
                                    </ol>
                                </div>
                            </li>`
            })
            // 标签赋值创建结构
            $("#mainList>.bigList").html(html);
            newData.forEach((el, index) => {
                $.ajax({
                        url: `http://chst.vip:1234/api/getcategory?titleid=${el.titleId}`
                    })
                    .then(res => {
                        console.log(res);
                        let smallList = ''
                        res.result.forEach((resel) => {
                            smallList +=
                                `<li><a href="./../pages/bijia.html?title=${resel.category}&categoryid=${resel.categoryId}">${resel.category}</a></li>`
                        })
                        // 标签赋值创建结构
                        $('.bigListLi>.smallList>ol').eq(index).html(smallList);

                    })
            })
            // 页面抽屉效果
            $(".smallListTitle").on('click', function () {
                $(this).next().slideToggle()
                $(this).css('color', 'gray');
                $(this).parent().siblings().find('.smallListTitle').next().hide(300)
                $(this).parent().siblings().find('.smallListTitle').css('color', 'black');
            })
        }

        $.ajax({
                url: "http://chst.vip:1234/api/getcategorytitle"
            })
            .then(res => {
                // console.log(res);
                menu(res.result)
            })

    })()

}


// gsproduct页面
function gsproduct() {
    (function () {
        //渲染商品列表函数
        function buildShop(shopid = 0, areaid = 0) {
            $.ajax({
                    url: `http://chst.vip:1234/api/getgsproduct?shopid=${shopid}&areaid=${areaid}`
                })
                .then(res => {
                    console.log(res);
                    newData = res.result
                    console.log(newData);
                    let html = "" //这个变量用于保存循环创建出来的结构字符串
                    newData.forEach(item => {
                        html +=
                            `<li><a href="">
                    <img src=${item.productImg} alt="">
                    <div>${item.productName}</div>
                    <p>${item.productPrice}</p>
                </a></li>`
                    })
                    $("#mainShopList>ul").html(html);
                })
        }
        // 初始渲染页面
        buildShop()

        //商店列表标题函数
        function buildChooseList1() {
            $.ajax({
                    url: `http://chst.vip:1234/api/getgsshop`
                })
                .then(res => {
                    console.log(res);
                    newData = res.result
                    console.log(newData);
                    let html = "" //这个变量用于保存循环创建出来的结构字符串
                    newData.forEach(item => {
                        html +=
                            `
                    <li shopid=${item.shopId}>${item.shopName}</li>
                `
                    })
                    $("#chooseList>.chooseList1").html(html);
                    // 商店列表标题点击事件
                    $(".chooseList1>li").click(function () {
                        // console.log($(this).attr('shopid'));
                        let shopid = $(this).attr('shopid');
                        buildShop(shopid)
                        $(".chooseList1").hide()
                        let text = $(this).text()
                        // console.log(text);
                        $('#chooseTitle>div').eq(0).text(text)
                    })
                })
        }
        //地区列表函数
        function buildChooseList2() {
            $.ajax({
                    url: `http://chst.vip:1234/api/getgsshoparea`
                })
                .then(res => {
                    console.log(res);
                    newData = res.result
                    console.log(newData);
                    let html = "" //这个变量用于保存循环创建出来的结构字符串
                    newData.forEach(item => {
                        html +=
                            `
                    <li areaid=${item.areaId}>${item.areaName}</li>
                `
                    })
                    $("#chooseList>.chooseList2").html(html);
                    // 地区列表点击事件
                    $(".chooseList2>li").click(function () {
                        // console.log($(this).attr('shopid'));
                        let areaid = $(this).attr('areaid');
                        buildShop(0, areaid)
                        $(".chooseList2").hide()
                        let text = $(this).text().substr(0, 2)
                        // console.log(text);
                        $('#chooseTitle>div').eq(1).text(text)
                    })
                })
        }

        // 选择标题部分事件
        $('#chooseTitle>div').eq(0).click(function () {
            $(".chooseList2").hide()
            buildChooseList1()
            $(".chooseList1").slideToggle()

        })

        $('#chooseTitle>div').eq(1).click(function () {
            $(".chooseList1").hide()
            buildChooseList2()
            $(".chooseList2").slideToggle()
        })

    })()
}


// moneyctrl页面
function moneyctrl (){
    (function () {
        //获取商品
        function shop(newData) {
            // newData = [...newData, ...data]
            // console.log(newData);
            let html = "" //这个变量用于保存循环创建出来的结构字符串
            newData.forEach(item => {
                html +=
                    `<li productId=${item.productId}>
                    <a href="#">
                        <div class="mainLeft">${item.productImgSm}</div>
                        <div class="mainRight">
                            <div class="mainRightTop">
                                <p>${item.productName}<span>${item.productPinkage}</span></p>
                            </div>
                            <div class="mainRightBottom">
                     <p>${item.productFrom} |${item.productTime}</p>
                       <span>${item.productComCount}</span>
                             </div>
                         </div>
                     </a>
            </li>`
            })
    
            $('mainShop>ul').html(html)
            let uu = document.querySelector('#mainShop ul')
            uu.innerHTML = html
            //获取Li元素,注册点击事件
            let lis = [...uu.children];
            // console.log(lis)
            lis.forEach(item => {
                item.onclick = function () {
                    //获取当前元素的couponId
                    let productid = this.getAttribute("productid")
                    // console.log(couponId)
                    //跳转到详情页
                    location.href = `./moneyctrlXiang.html?productid=${productid}`
                }
            })
    
    
        }
        // 页面初始结构
        $.ajax({
                url: "http://chst.vip:1234/api/getmoneyctrl",
                data: {
                    pageid: 0
                }
            })
            .then(res => {
                // console.log(res);
                shop(res.result)
                //循环数据 创建结构
            })
        //创建底部分页的选项
        $.ajax({
                url: "http://chst.vip:1234/api/getmoneyctrl",
    
            })
            .then(res => {
                // console.log(res);
                let count = Math.ceil(res.totalCount / res.pagesize)
                let page = document.querySelector('.page')
                // console.log(count);
                let pageText = ''
                for (i = 1; i <= count; i++) {
                    pageText += `<option value="" class="page">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;${i}/${count}</option>`
                }
                page.innerHTML = pageText;
                pageChange(count)
    
            })
            //翻页器函数
            function pageChange(count) {
                // console.log(count);
                let pageid = 0;
                // 翻页点击事件
                $('.page').click(() => {
                    // console.log($(".page")[0].selectedIndex,'---------');
                    pageid = $(".page")[0].selectedIndex //获取索引
                    $.ajax({
                            url: "http://chst.vip:1234/api/getmoneyctrl",
                            data: {
                                pageid
                            }
                        })
                        .then(res => {
                            console.log(res);
                            shop(res.result);
                            //循环数据 创建结构
                        })
                    if (pageid == 0) {
                        $('.pagePrev')[0].setAttribute('disabled', 'disabled')
                    } else if (pageid == count-1) {
                        $('.pageNext')[0].setAttribute('disabled', 'disabled')
                    } else {
                        // console.log('逻辑进来了');
                        $('.pagePrev').removeAttr('disabled')
                        $('.pageNext').removeAttr('disabled')
                    }
                    // console.log(pageid);
                })
                // 下一页点击事件
                $('.pageNext').click(() => {
                    $('.pagePrev').removeAttr('disabled')
                    pageid++ //每次被点击的时候 让id自加 请求不同的数据
                    if (pageid <= count-1) {
                        $('select.page').get(0).options[pageid].selected = true
                    }
                    // console.log('下一页' + pageid);
                    if (pageid == count-1) { //当id大于14的时候 停止发送请求
                        $('.pageNext')[0].setAttribute('disabled', 'disabled')
                        // pageid=13;
                        // return
                    }
                    $.ajax({
                            url: "http://chst.vip:1234/api/getmoneyctrl",
                            data: {
                                pageid
                            }
                        })
                        .then(res => {
                            // console.log(res);
                            shop(res.result);
                            //循环数据 创建结构
                        })
                })
                // 上一页点击事件
                $('.pagePrev').click(() => {
                    $('.pageNext').removeAttr('disabled')
                    pageid--; //每次被点击的时候 让id自减 请求不同的数据
                    if (pageid >= 0) {
                        $('.page').get(0).options[pageid].selected = true
                    }
                    // console.log("上一页" + pageid);
                    if (pageid == 0) { //当id=0的时候 禁用按钮
                        $('.pagePrev')[0].setAttribute('disabled', 'disabled')
                    }
                    $.ajax({
                            url: "http://chst.vip:1234/api/getmoneyctrl",
                            data: {
                                pageid
                            }
                        })
                        .then(res => {
                            // console.log(res);
                            shop(res.result);
                            //循环数据 创建结构
                        })
                })
            }
    })()
}